@extends('default.layouts.adminPublic')
@section('title', '友情链接列表')
@section('headcss')
    @parent
    <link rel="stylesheet" href="{{asset('/default/css/admin/indexList.css')}}">
    @endsection
    @section('content')
            <!--导航开始-->
    <div class="crumb_warp">
        <i class="fa fa-home"></i> <a href="{{url('admin/links')}}">首页</a> &raquo; 友情链接列表
    </div>
    <!--导航结束-->
    <!--结果集标题与导航组件 开始-->
    <div class="con">
        <div class="conMain">
            <div class="result_wrap">
                <div class="search">
                    <form name="Formso" id="Formso" action="{{url('admin/link_list')}}" method="post">
                        {{csrf_field()}}
                        <span>关键字：</span>
                        <span><input name="keyword" class="keyword" id="keyword" placeholder="请输入广告名称" type="text"></span>
                        <select name="link_site" id="link_site" style="width:140px;">
                            <option value="">请选择广告站点</option>
                            @if(count($link_site) > 0)
                                @foreach($link_site as $v )
                                    <option value="{{$v->id}}">{{$v->link_name}}</option>
                                @endforeach
                            @endif
                        </select>
                        <span><input name="submit" class="skeyword" value="搜索" type="submit"></span>
                    </form>
                </div>
                <div class="message" style="margin-top: 15px;">
                    <p><span style="margin-right: 20px; font-size: 15px;"><a href="{{url('admin/links/create')}}"><i class="fa fa-plus"></i>添加友情链接</a></span>
                        <span>目前共查找到<strong>{{$links->total()}}</strong>个友情链接！且每页显示友情链接记录{{$links->perPage()}}个。</span>
                    </p>
                </div>

            </div>
            <div class="manage">
                @include('flash::message')
            </div>
            <div class="conInfo">
                <form name="thisForm" id="thisForm" action="" method="post">
                    {{csrf_field()}}
                    <div class="conList" id="conList">
                        <dl class="one">
                            <dt><input name="selectall" type="checkbox" value="1" onclick="CheckAll(this)" /></dt>
                            <dd class="link1">友情名称</dd>
                            <dd class="link2">友情地址</dd>
                            <dd class="link3">友情站点</dd>
                            <dd class="link4">友情排序</dd>
                            <dd class="link5">友情操作</dd>
                        </dl>
                        @if($links->count() > 0 )
                            @foreach($links as $v)
                                <dl id="list{{$v->id}}">
                                    <dt><input name="selected_id[]" type="checkbox" value="{{$v->id}}" /></dt>
                                    <dd class="link1"><a href="{{$v->url}}" target="_blank">{{str_limit($v->link_name,24)}}</a></dd>
                                    <dd class="link2">{{str_limit($v->link_url,40)}}</dd>
                                    <dd class="link3">{{$v->link_site}}</dd>
                                    <dd class="link4">{{$v->link_sort}}</dd>
                                    <dd class="link5">
                                        <span><a href="{{url('admin/links/'.$v->id.'/edit')}}">修改友情链接</a></span>
                                        <span><a onclick="delSite({{$v->id}})">删除友情链接</a></span>
                                    </dd>
                                </dl>
                            @endforeach
                        @else
                            <div class="nullcon">对不起！没有友情链接记录！</div>
                        @endif
                        <dl class="last">
                            <dt>
                                <input name="selectall" id="selectall" type="checkbox" value="1" onclick="CheckAll(this)" />
                                <label for="selectall">全选</label>
                            </dt>
                        </dl>
                    </div>
                </form>
                <div class="page_list" style="width: 100%; float: left; margin-top:15px;">
                    {!! $links->links() !!}
                </div>
            </div>

            <div class="stopper" style="margin-top:10px; border-top: 1px solid #e5e5e5"></div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->
@endsection

@section('footerjs')
    @parent
    <script>
        //全选中与全不选中职位资料
        function CheckAll(form){
            if (form.checked==true){
                for (var i=0;i<document.thisForm.elements.length;i++){
                    var e = document.thisForm.elements[i];
                    if (e.name == 'selectedid' || e.name=='selected_id[]' || e.name=='selectall')
                        e.checked=true;
                }
            }else{
                for (var i=0;i<document.thisForm.elements.length;i++){
                    var e = document.thisForm.elements[i];
                    if (e.name == 'selectedid' || e.name=='selected_id[]' || e.name=='selectall')
                        e.checked=false;
                }
            }
        }
        //删除友情
        function delSite(id) {
            layer.confirm('您确定要删除这个友情链接吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post("{{url('admin/links/')}}/" + id, {'_method': 'delete','_token': "{{csrf_token()}}"}, function (data) {
                    if (data.status == 0) {
                        layer.msg(data.msg, {icon: 6,time:1500});
                        $("#thisForm").find('#conList').find("#list"+id).remove();
                    } else {
                        layer.msg(data.msg, {icon: 5,time:1500});
                    }
                });
            });
        }
    </script>
@endsection